package com.woniuxy.oa.service.impl;

import com.woniuxy.oa.dao.SigninDAO;
import com.woniuxy.oa.entity.Signin;
import com.woniuxy.oa.service.SigninService;
import com.woniuxy.oa.util.OaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Mr X
 */
@Service
@Transactional
public class SigninServiceImpl implements SigninService {
    @Autowired
    private SigninDAO signinDAO;

    /**
     * 增加打卡记录
     *
     * @param signin
     */
    @Override
    public void add(Signin signin) {
        int rHours = 9, rMinute = 20;
        int hours = 0, minute = 0;
        String _hours = OaUtil.getNow().substring(11, 13);
        String _minute = OaUtil.getNow().substring(14, 16);
        if (_hours.substring(0, 1).equals("0")) {
            hours = Integer.parseInt(_hours.substring(1));
        }
        if (_minute.substring(0, 1).equals("0")) {
            minute = Integer.parseInt(_minute.substring(1));
        }
        signin.setId(OaUtil.getId());
        if (hours > rHours && minute > rMinute) {
            signin.setUpTimeStatus("2");
        }
        signin.setUpTimeStatus("1");
        signinDAO.add(signin);
    }

    /**
     * 通过员工ID查询打卡记录
     *
     * @param empid
     * @return
     */
    @Override
    public List<Signin> getByEmpId(String empid) {
        return signinDAO.getByEmpId(empid);
    }
}
